<div class="TB_AddQuestion">

	<script language="JavaScript" type="text/javascript">
		function CheckAddQuestionForm()
		{
			// Make sure that all of the form variables, etc are valid
			var f = document.frmAddQuestion;
			
			var aText = '';

			if (typeof(wysiwyg) != 'undefined') {
				aText = wysiwyg.getHTMLContent();
			} else {
				var tas = document.getElementsByTagName('textarea');
				for (i=0; i<tas.length; i++) {
					if (tas[i].name == "wysiwyg_html") {
						aText = tas[i].value;
						break;
					}
				}
			}

			try {
				aText = document.getElementById("editorContainer").contentWindow.wysiwyg.getHTMLContent();
			} catch (e) {
				ifObj = document.getElementById("editorContainer").contentWindow;
				aText = ifObj.document.getElementById("contentPlainText").value;
			}
			document.getElementById("wysiwyg_html").value = aText;
			
			aText = aText.replace('br/', "");
			aText = aText.replace('>', "");
			aText = aText.replace('<', "");
			aText = aText.replace('&nbsp;', "");
			aText = aText.replace(' ', "");
			
			if (f.title.value.length == 0) {
				alert('%%LNG_EnterQuestionTitle%%');
				f.title.focus();
				f.title.select();
				return false;
			}

			if (document.getElementById("category").selectedIndex == -1) {
				alert('%%LNG_ChooseQuestionCategory%%');
				document.getElementById("category").focus();
				return false;
			}

			if (aText == '&nbsp;' || aText == '<br/>' || aText == '' || aText == '&nbsp;<br/>') {
				alert('%%LNG_NoAnswer%%');
				return false;
			}

			if (isNaN(f.sortorder.value)) {
				alert('%%LNG_BadSort%%');
				ShowTab(1);
				f.sortorder.focus();
				f.sortorder.select();
				return false;
			}

			// If they have the last updated field checked then we need to clear
			// the value so that it gets a new value upon submission
			if ($('#lastupdatedcheck') && $('#lastupdatedcheck').attr('checked') == true) {
				$('#lastupdated').val('');
			}

			// Select all the related questions so they get sent through in the
			// post request only if we arnt auto detecting related questions
			if (!$("#detectrelated").attr('checked')) {
				SelectAllOptions('questionsrelated');
			}

			// If this is an email to submitter form, check if the user will
			// be able to see it or not
			if (f.emailtosubmitter) {
				if (!f.visible.checked) {
					return confirm('%%LNG_SubmittedQuestionNotVisible%%');
				}

				if (document.getElementById("category").selectedIndex == 0) {
					return confirm('%%LNG_SubmittedQuestionNoParentCategory%%');
				}

			}

			if (($("#restrictPrivate").checked) && ($("#groups").selectedIndex == -1)) {
				alert("%%LNG_ErrArticleGroupRestrictNoChosen%%");
				return false;
			}

			// Everything is OK, return true
			return true;
		}

		function SelectAllOptions(id)
		{
			var rel = document.getElementById(id);
			for (i=0; i < rel.options.length; i++) {
				rel.options[i].selected = true;
			}
		}
	
		function ToggleRelatedQuestions()
		{
			if ($('#detectrelated').attr("checked")) {
				$('#related_category_cont').hide();
			} else {
				$('#related_category_cont').show();
			}
		}
		
		function MoveBetweenSelects(from, toName)
		{

			if (document.getElementById('related_category').selectedIndex <= 0) {
				return false;
			}

			if (from.selectedIndex > -1) {
				var to = document.getElementById(toName);

				// Add the option to the new select
				t = from[from.selectedIndex].text;
				v = from[from.selectedIndex].value;
				to.options[to.options.length] = new Option(t, v);

				// Remove the option from the old select
				from[from.selectedIndex] = null;
				//from.options.length--;
			}
		}

		var req;
		var url = '%%GLOBAL_pathToKB%%/admin/remote.php';

		function DoCallback(data)
		{
			if (!req) {
				// branch for native XMLHttpRequest object
				if (window.XMLHttpRequest) {
					req = new XMLHttpRequest();
				// branch for IE/Windows ActiveX version
				} else if (window.ActiveXObject) {
					req = new ActiveXObject('Microsoft.XMLHTTP')
				}
			}
			req.onreadystatechange = processReqChange;
			req.open('POST', url, true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(data);
		}


		function processReqChange() {
			// only if req shows 'loaded'
			if (req.readyState == 4) {
				// only if 'OK'
				if (req.status == 200) {
					ProcessData(req.responseXML);
				} else {
					alert('There was a problem retrieving the XML data:\n' +
						req.responseText);
				}
			}
		}
	
		function GetQuestions(selObj)
		{
			// Clear the questions list
			rel = document.getElementById("related_category_questions");
			rel.options.length = 0;

			cat = document.getElementById("related_category");

			if (cat.selectedIndex > 0) {
				// Get the products using XML
				var catid = cat.options[cat.selectedIndex].value;

				rel.options[0] = new Option("%%LNG_Loading%%", "-1");
				rel.options.length = 1;
				window.status = "%%LNG_RelatedQuestionWaitMessage%%";
				DoCallback("type=questionlist&categoryid="+catid);
				window.status = "";
			}
		}

		function OptionInSelect(id, select)
		{
			for (var i=0; i< select.options.length; i++) {
				if (select.options[i].value == id) return true;
			}
			return false;
		}

		function ProcessData(data)
		{
			var rel = document.getElementById("related_category_questions")
			var related_to_submit = document.getElementById('questionsrelated');
			var root = data.documentElement;
			var items = root.childNodes;
			var added=0;

			rel.options[0] = null;
			rel.options.length = 0;

			for (i = 0; i < items.length; i++) {
				var text = '';
				var value = '';
				for (j = 0; j < items[i].attributes.length; j++) {
					switch (items[i].attributes[j].nodeName) {
						case 'text':
							text = items[i].attributes[j].value;
							break;
						case 'id':
							value = items[i].attributes[j].value;
							break;
					}
				}


				// Only add questions to our list of questions in the category
				// if the question is not already in our list. This covers both
				// the case of loading up questions from the database and
				// browsing to another category with the same question.
				if (!OptionInSelect(value, related_to_submit)) {
					rel.options[added] = new Option(text, value);
					added++;
				}
			}
			rel.options.length = added;
			req=null;
		}
		
		function ToggleExpiryDate(Status)
		{
			if(Status)
			{
				document.getElementById("endday").disabled = false;
				document.getElementById("endmonth").disabled = false;
				document.getElementById("endyear").disabled = false;

				document.getElementById("endtime").disabled = false;

				document.getElementById("tdExpiryDate").disabled = false;
			}
			else
			{
				document.getElementById("endday").disabled = true;
				document.getElementById("endmonth").disabled = true;
				document.getElementById("endyear").disabled = true;

				document.getElementById("endtime").disabled = true;

				document.getElementById("tdExpiryDate").disabled = true;
			}
		}
		
		function GroupCheck(chkd) {
			$("#groups").disabled = !chkd;

			if (chkd) {
				$("#groupBlock").show();
				$("#restrictPrivate").attr("checked","checked");
			} else {
				$("#groupBlock").hide();
				$("#restrictPublic").attr("checked","checked");
			}
		}
		
		function ShowTab(T)
		{
			i = 0;
			while (document.getElementById("tab" + i) != null) {
//				document.getElementById("div" + i).style.display = "none";
				document.getElementById("tab" + i).className = "";
				$("#div" + i).hide();
				i++;
			}

			if (T == 1) {
				ToggleExpiryDate(document.getElementById("expires").checked);
				GroupCheck(%%GLOBAL_HasGroups%%);
				if (%%GLOBAL_HasGroups%%) {
					$("#restrictPrivate").attr("checked","checked");
				}
			}
			
			$("#div" + T).show();
			document.getElementById("tab" + T).className = "active";
		}
		
		function ShowMoreAttachments()
		{
			document.getElementById("trMoreAttachments").style.display = "none";
			// Simple test for ie ... if its ie then display the tr as a block
			// otherwise display it as a table-row
			if (document.all) {
				document.getElementById("trAttachments").style.display = "block";
			} else {
				document.getElementById("trAttachments").style.display = "table-row";
			}
		}
		

		function ValidateForm(callback) {
			returnValue = callback();

			if (window.event) {
				window.event.returnValue = returnValue;
			} else {
				return returnValue;
			}
		}
	</script>
	<form action="%%GLOBAL_pathToKB%%/admin/incadd_get.php?todo=%%GLOBAL_FormAction%%" enctype="multipart/form-data" name="frmAddQuestion" method="post" accept-charset="%%GLOBAL_charset%%" onsubmit="return ValidateForm(CheckAddQuestionForm);">
	<input type="hidden" name="originCid" value="%%GLOBAL_CategoryId%%" />
	<input type="hidden" id="wysiwyg_html" name="wysiwyg_html" value="" />
	<table cellspacing="0" cellpadding="0" border="0">
	<tr>
		<td>
			<div class="HeaderBox" style="width: 99%;">%%GLOBAL_Message%%</div>
			<div style="margin-top:10px;margin-bottom:10px;">
				<input type="submit" name="SubmitButton1" value="%%LNG_Save%%" class="FormButton" />
				<input type="button" name="CancelButton1" value="%%LNG_Cancel%%" class="FormButton" onClick="if(confirm('%%GLOBAL_CancelMessage%%')){tb_remove();}" />
			</div>
		</td>
	</tr>
	<tr>
		<td>
			<ul id="tabnav">
				<li><a href="#" class="active" id="tab0" onclick="ShowTab(0)">%%LNG_QuestionContent%%</a></li>
				<li><a href="#" id="tab1" onclick="ShowTab(1)">%%LNG_QuestionAdvanced%%</a></li>
			</ul>
		</td>
	</tr>
	<tr>
		<td>
			<div id="div0">
				<table >
					<tr>
						<td class="HeadingQuestionForm" colspan="2">%%LNG_NewQuestionDetails%%</td>
					</tr>
					<tr>
						<td class="FieldLabelQuestionForm">
							<span class="Required">*</span>&nbsp;%%LNG_QuestionTitle%%:
						</td>
						<td>
							<input type="text" name="title" id="title" class="Field300" value="%%GLOBAL_QuestionTitle%%">
							<img onmouseout="HideHelp(this)" onmouseover="ShowHelp(this, '%%LNG_QuestionTitle%%', '%%LNG_QuestionTitleHelp%%')" src="%%GLOBAL_pathToKB%%/admin/images/help.gif" width="24" height="16" border="0" alt="help">
						</td>
					</tr>
					<tr>
						<td class="FieldLabelQuestionForm" valign="top">
							<span class="Required">*</span>&nbsp;%%LNG_QuestionCategory%%:
						</td>
						<td>
							<select size="10" name="category[]" id="category" class="Field300" style="height:115px;" multiple >
								%%GLOBAL_CategoryOptions%%
							</select>
							<img onmouseout="HideHelp(this)" onmouseover="ShowHelp(this, '%%LNG_QuestionCategory%%', '%%LNG_QuestionCategoryHelp%%')" src="%%GLOBAL_pathToKB%%/admin/images/help.gif" width="24" height="16" border="0" alt="help" align="top" />
						</td>
					</tr>
					%%Panel.QuestionStatus%%
					<tr>
						<td class="FieldLabelQuestionForm">
							&nbsp;&nbsp;&nbsp;%%LNG_QuestionVisible%%:
						</td>
						<td>
							<input type="checkbox" name="visible" checked value="ON" %%GLOBAL_DisableVisible%% id="chkvis">
							<label for="chkvis">%%LNG_QuestionVisibleYes%%</label>
							<img onMouseOut="HideHelp(this)" onMouseOver="ShowHelp(this, '%%LNG_QuestionVisible%%', '%%LNG_QuestionVisibleHelp%%')" src="%%GLOBAL_pathToKB%%/admin/images/help.gif" width="24" height="16" border="0" alt="help">
						</td>
					</tr>
					<tr>
						<td class="FieldLabelQuestionForm">
							&nbsp;&nbsp;&nbsp;%%LNG_QuestionsFeatured%%:
						</td>
						<td>
	<input type="checkbox" name="featured" %%GLOBAL_CheckFeatured%% value="1" %%GLOBAL_DisableFeatured%% id="chkfeatured">
							<label for="chkfeatured">%%LNG_DisableFeaturedYes%%</label>
							<img onMouseOut="HideHelp(this)" onMouseOver="ShowHelp(this, '%%LNG_QuestionsFeatured%%', '%%LNG_QuestionsFeaturedHelp%%')" src="%%GLOBAL_pathToKB%%/admin/images/help.gif" width="24" height="16" border="0" alt="help">					</td>
					</tr>
				</table>

				<table >
				<tr>
					<td class="HeadingQuestionForm" colspan="2">%%LNG_NewQuestionContent%%</td>
				</tr>
				<tr>
					<td class="FieldLabelQuestionForm" valign="top">
						<span class="Required">*</span>&nbsp;%%LNG_QuestionAnswer%%:
					</td>
					<td>
						%%GLOBAL_WYSIWYG%%
						<span id="tt3"></span>
					</td>
				</tr>
				<tr>
					<td class="FieldLabelQuestionForm">
						&nbsp;&nbsp;&nbsp;%%LNG_metaKeywords%%:
					</td>
					<td>
						<input type="text" name="metakeywords" class="Field300" value="%%GLOBAL_MetaKeywords%%" maxlength="250">
						<img onmouseout="HideHelp(this)" onmouseover="ShowHelp(this, '%%LNG_metaKeywords%%', '%%LNG_metaKeywordsHelp%%')" src="%%GLOBAL_pathToKB%%/admin/images/help.gif" width="24" height="16" border="0" alt="help" />
					</td>
				</tr>
				<tr>
					<td class="FieldLabelQuestionForm" valign="top">
						&nbsp;&nbsp;&nbsp;%%LNG_metaDescription%%:
					</td>
					<td class="Field">
						<textarea name="metadescription" class="Field300">%%GLOBAL_MetaDescription%%</textarea>
						<img onmouseout="HideHelp(this)" onmouseover="ShowHelp(this, '%%LNG_metaDescription%%', '%%LNG_metaDescriptionHelp%%')" src="%%GLOBAL_pathToKB%%/admin/images/help.gif" width="24" height="16" border="0" alt="help">
					</td>
				</tr>
				</table>
				<table >
				<tr>
					<td class="HeadingQuestionForm" colspan="2">%%LNG_QuestionAttachments%%</td>
				</tr>
				<tr>
					<td class="FieldLabelQuestionForm">
						&nbsp;&nbsp;&nbsp;%%LNG_QuestionAttachment%%:
					</td>
					<td class="Field">
						<input type="file" name="attachment[]" class="Field">
						<img onmouseout="HideHelp(this)" onmouseover="ShowHelp(this, '%%LNG_QuestionAttachment%%', '%%LNG_QuestionAttachmentHelp%%')" src="%%GLOBAL_pathToKB%%/admin/images/help.gif" width="24" height="16" border="0" alt="help">
					</td>
				</tr>
				<tr id="trMoreAttachments">
					<td class="FieldLabelQuestionForm">
						&nbsp;
					</td>
					<td c>
						<a href="javascript:void(0)" onclick="ShowMoreAttachments()">%%LNG_MoreAttachments%%</a>
					</td>
				</tr>
				<tr id="trAttachments" style="display:none">
					<td class="FieldLabelQuestionForm" >
						&nbsp;
					</td>
					<td class="Field">
						<input type="file" name="attachment[]" class="Field300"><br />
						<input type="file" name="attachment[]" class="Field300"><br />
						<input type="file" name="attachment[]" class="Field300"><br />
						<input type="file" name="attachment[]" class="Field300">
					</td>
				</tr>
				%%GLOBAL_ExistingAttachments%%
				<tr>
					<td colspan="2">&nbsp;</td>
				</tr>
				</table>

			</div>

			<div id="div1" style="display: none">
				<table >
				<tr>
					<td class="HeadingQuestionForm" colspan=2>%%LNG_DateAndDisplay%%</td>
				</tr>
				<tr>
					<td class="FieldLabelQuestionForm" style="width:193px;">
						&nbsp;&nbsp;&nbsp;%%LNG_ArticleStartDate%%:
					</td>
					<td>
						<select name="startday" id="startday" class="Field">
							%%GLOBAL_StartDayOptions%%
						</select>
						<select name="startmonth" id="startmonth" class="Field">
							%%GLOBAL_StartMonthOptions%%
						</select>
						<select name="startyear" id="startyear" class="Field">
							%%GLOBAL_StartYearOptions%%
						</select>
						&nbsp;&nbsp;

						<select id="starttime" name="starttime" size="1" class="Field">
						%%GLOBAL_StartTimeList%%
						</select>

						<img onMouseOut="HideHelp(this)" onMouseOver="ShowHelp(this, '%%LNG_ArticleStartDate%%', '%%LNG_ArticleStartDateHelp%%')" src="%%GLOBAL_pathToKB%%/admin/images/help.gif" width="24" height="16" border="0">
					</td>
				</tr>
				<tr>
					<td class="FieldLabelQuestionForm" style="width:193px;">
						&nbsp;&nbsp;&nbsp;%%LNG_ArticleExpiry%%:
					</td>
					<td>
						<input onclick="ToggleExpiryDate(this.checked)" type="checkbox" name="expires" value="on" id="expires" %%GLOBAL_DoesExpire%%>
						<label for="expires">%%LNG_YesExpires%%</label>
						</select>
						<img onMouseOut="HideHelp(this)" onMouseOver="ShowHelp(this, '%%LNG_ArticleExpiry%%', '%%LNG_ArticleExpiryHelp%%')" src="%%GLOBAL_pathToKB%%/admin/images/help.gif" width="24" height="16" border="0">
					</td>
				</tr>
				<tr>
					<td class="FieldLabelQuestionForm" id="tdExpiryDate"  style="width:193px;">
						&nbsp;&nbsp;&nbsp;%%LNG_ArticleExpiryDate%%:
					</td>
					<td>
						<img src="%%GLOBAL_pathToKB%%/admin/images/nodejoin.gif" width="20" height="20">
						<select %%GLOBAL_ExpireDateDisabled%% name="endday" id="endday" class="Field">
							%%GLOBAL_EndDayOptions%%
						</select>
						<select %%GLOBAL_ExpireDateDisabled%% name="endmonth" id="endmonth" class="Field">
							%%GLOBAL_EndMonthOptions%%
						</select>
						<select %%GLOBAL_ExpireDateDisabled%% name="endyear" id="endyear" class="Field">
							%%GLOBAL_EndYearOptions%%
						</select>
							&nbsp;&nbsp;

						<select id="endtime" name="endtime" size="1" class="Field">
						%%GLOBAL_EndTimeList%%
						</select>

						<img onmouseout="HideHelp(this);" onmouseover="ShowHelp(this, '%%LNG_ArticleExpiry%%', '%%LNG_ArticleEndDateHelp%%')" src="%%GLOBAL_pathToKB%%/admin/images/help.gif" width="24" height="16" border="0">
					</td>
				</tr>
				<tr>
					<td class="FieldLabelQuestionForm" style="width:193px;">
						&nbsp;&nbsp;&nbsp;%%LNG_QuestionSortOrder%%:
					</td>
					<td>
						<input type="text" name="sortorder" class="Field50" value="%%GLOBAL_SortOrder%%">
						<img onMouseOut="HideHelp(this)" onMouseOver="ShowHelp(this, '%%LNG_QuestionSortOrder%%', '%%LNG_QuestionSortOrderHelp%%')" src="%%GLOBAL_pathToKB%%/admin/images/help.gif" width="24" height="16" border="0" alt="help">
					</td>
				</tr>
				</table>

				<table>
				<tr>
					<td class="HeadingQuestionForm" colspan="2">%%LNG_QuestionRelatedTitle%%</td>
				</tr>
				<tr>
					<td class="FieldLabelQuestionForm" valign="top" style="width:193px;">
						&nbsp;&nbsp; %%LNG_QuestionRelated%%:
					</td>
					<td>
						<div style="float:left;">
							<input onclick="ToggleRelatedQuestions(this.checked)" type="checkbox" name="detectrelated" id="detectrelated" value="1" %%GLOBAL_DetectRelated%%> <label for="detectrelated">%%LNG_YesDetectRelatedQuestions%%</label>
							<img onmouseout="HideHelp(this)" onMouseOver="ShowHelp(this, '%%LNG_QuestionDetectRelated%%', '%%LNG_QuestionDetectRelatedHelp%%')" src="%%GLOBAL_pathToKB%%/admin/images/help.gif" width="24" height="16" border="0" alt="help">
						</div>

						<br clear="all" />

						<div id="related_category_cont">
							<select name="related_category" id="related_category" class="Field300" onchange="GetQuestions(this)">
								<option selected value="0">%%LNG_SelectACategory%%</option>
								%%GLOBAL_RelatedCategoryOptions%%
							</select>
							<br clear="all" />

							<select size="5" name="related_category_questions" id="related_category_questions" class="Field300" ondblclick="javascript: MoveBetweenSelects(this, 'questionsrelated');">
							</select>
							<div>%%LNG_RelatedQuestionDoubleClickToAdd%%</div>
							<select size="5" name="questionsrelated[]" id="questionsrelated" class="Field300" multiple="multiple" ondblclick="javascript: MoveBetweenSelects(this, 'related_category_questions');">
								%%GLOBAL_RelatedQuestions%%
							</select>
							<div style="padding:5px;">%%LNG_RelatedQuestionDoubleClickToRemove%% <img onmouseout="HideHelp(this)" onmouseover="ShowHelp(this, '%%LNG_QuestionRelated%%', '%%LNG_QuestionRelatedHelp%%')" src="%%GLOBAL_pathToKB%%/admin/images/help.gif" width="24" height="16" border="0" alt="help" align="top">
</div>

						</div>
					</td>
				</tr>
				</table>
				<table border="0" cellpadding="2"  style="display: %%GLOBAL_CFDisplay%%;">
					<tr>
						<td class="HeadingQuestionForm" colspan="2">%%LNG_CustomFields%%</td>
					</tr>
					%%GLOBAL_CustomFields%%
				</table>

				%%Panel.UserGroupsCategoryArticle%%

			</div>
		</td>
	</tr>
	<tr>
		<td style="padding-left: 125px">
			<br />
			<input type="submit" name="SubmitButton2" value="%%LNG_Save%%" class="FormButton">
			<input type="button" name="CancelButton2" value="%%LNG_Cancel%%" class="FormButton" onclick="if(confirm('%%GLOBAL_CancelMessage%%')){tb_remove();}">
			<br />
			<br />
		</td>
	</tr>


	<tr>
		<td class="Gap"></td>
	</tr>
	</table>
	</form>
</div>